home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QRZ! Ham Radio 8
/
QRZ Ham Radio Callsign Database - Volume 8.iso
/
pc
/
files
/
t_unix
/
j109lxa4.tar
/
ipdump.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-06-04
|
3KB
|
176 lines
/* IP header tracing routines
* Copyright 1991 Phil Karn, KA9Q
*/
/* Mods by PA0GRI */
#include <stdio.h>
#include "global.h"
#include "config.h"
#include "mbuf.h"
#include "internet.h"
#include "iface.h"
#include "ip.h"
#include "trace.h"
#include "netuser.h"
void
#ifdef MONITOR
ip_dump(fp,bpp,check,mon)
int mon;
#else
ip_dump(fp,bpp,check)
#endif
FILE *fp;
struct mbuf **bpp;
int check;
{
struct ip ip;
int16 ip_len;
int16 length;
int16 csum;
if(bpp == NULLBUFP || *bpp == NULLBUF)
return;
#ifdef MONITOR
if (!mon)
#endif
fprintf(fp,"IP: ");
/* Sneak peek at IP header and find length */
ip_len = ((*bpp)->data[0] & 0xf) << 2;
if(ip_len < IPLEN){
fprintf(fp,"bad header\n");
return;
}
if(check)
csum = cksum(NULLHEADER,*bpp,ip_len);
else
csum = 0;
ntohip(&ip,bpp); /* Can't fail, we've already checked ihl */
/* Trim data segment if necessary. */
length = ip.length - ip_len; /* Length of data portion */
trim_mbuf(bpp,length);
#ifdef MONITOR
if (!mon)
#endif
fprintf(fp,"len %u ",ip.length);
fprintf(fp,"%s",inet_ntoa(ip.source));
#ifdef MONITOR
if (mon)
fprintf(fp, "->%s", inet_ntoa(ip.dest));
else
#endif
fprintf(fp,"->%s ihl %u ttl %u",
inet_ntoa(ip.dest),ip_len,uchar(ip.ttl));
#ifdef MONITOR
if (!mon)
#endif
if(ip.tos != 0)
fprintf(fp," tos %u",uchar(ip.tos));
if(ip.offset != 0 || ip.flags.mf)
fprintf(fp," id %u offs %u",ip.id,ip.offset);
if(ip.flags.congest)
fprintf(fp," CE");
if(ip.flags.df)
fprintf(fp," DF");
if(ip.flags.mf){
fprintf(fp," MF");
check = 0; /* Bypass host-level checksum verify */
}
if(csum != 0)
fprintf(fp," CHECKSUM ERROR (%u)",csum);
if(ip.offset != 0){
fprintf(fp, "\n");
return;
}
switch(uchar(ip.protocol)){
case TCP_PTCL:
#ifdef MONITOR
if (mon)
fprintf(fp, " TCP ");
else
#endif
fprintf(fp," prot TCP\n");
#ifdef MONITOR
tcp_dump(fp,bpp,ip.source,ip.dest,check,mon);
#else
tcp_dump(fp,bpp,ip.source,ip.dest,check);
#endif
break;
case UDP_PTCL:
#ifdef MONITOR
if (mon)
fprintf(fp, " UDP ");
else
#endif
fprintf(fp," prot UDP\n");
#ifdef MONITOR
udp_dump(fp,bpp,ip.source,ip.dest,check,mon);
#else
udp_dump(fp,bpp,ip.source,ip.dest,check);
#endif
break;
case ICMP_PTCL:
#ifdef MONITOR
if (mon)
fprintf(fp, " ICMP ");
else
#endif
fprintf(fp," prot ICMP\n");
#ifdef MONITOR
icmp_dump(fp,bpp,ip.source,ip.dest,check,mon);
#else
icmp_dump(fp,bpp,ip.source,ip.dest,check);
#endif
break;
case IP_PTCL:
#ifdef MONITOR
if (mon)
fprintf(fp, " IP ");
else
#endif
fprintf(fp," prot IP\n");
#ifdef MONITOR
ip_dump(fp,bpp,check,mon);
#else
ip_dump(fp,bpp,check);
#endif
break;
#ifdef AX25
case AX25_PTCL:
#ifdef MONITOR
if (mon)
fprintf(fp, " AX25 ");
else
#endif
fprintf(fp," prot AX25\n");
#ifdef MONITOR
ax25_dump(fp,bpp,check,mon);
#else
ax25_dump(fp,bpp,check);
#endif
break;
#endif
#ifdef RSPF
case RSPF_PTCL:
#ifdef MONITOR
if (mon)
fprintf(fp, " RSPF\n");
else
#endif
fprintf(fp," prot RSPF\n");
#ifdef MONITOR
rspf_dump(fp,bpp,ip.source,ip.dest,check,mon);
#else
rspf_dump(fp,bpp,ip.source,ip.dest,check);
#endif
break;
#endif
default:
fprintf(fp," prot %u\n",uchar(ip.protocol));
break;
}
}